import React, { useEffect, useState } from "react";
import store from "../../redux/store";
import {
  addAction,
  timeAction,
  asyncless,
} from "../../redux/reducer/countReducer";
import { zanAdd, zanless } from "../../redux/reducer/zanReducer";
export default function Redux() {
  // let [data, setdata] = useState("");

  let add = (num) => {
    return () => {
      store.dispatch(addAction(num));
    };
  };
  let addtime = () => {
    timeAction(1);
  };

  let lesstime = () => {
    asyncless(1);
  };
  // useEffect(() => {
  //   store.subscribe(() => {
  //     setdata({});
  //   });
  // });
  let { count, zan } = store.getState();
  console.log(store.getState());
  let zanadd = () => {
    store.dispatch(zanAdd(1));
  };
  return (
    <div>
      <h1>redux 中的数据是：{count}</h1>
      <button onClick={add(1)}>点击+1</button>
      <button onClick={addtime}>1秒后加1</button>
      <button onClick={lesstime}>1秒后减1</button>
      <br />
      <br />
      <hr />
      <h1>赞的个数:{zan}</h1>
      <button onClick={zanadd}>点击+1</button>
    </div>
  );
}
